<?php
/**
 * Created by PhpStorm.
 * User: lyon
 * Date: 16-12-10
 * Time: 上午10:16
 */
class Count
{
    public static $INFO = [];
    public $success_page;
    public $error_page;
    public $begin_time;
    public $now_time;
    public $memory_use;
    public static function _init()
    {
        self::$INFO['success_page'] = 0;
        self::$INFO['error_page'] = 0;
        self::$INFO['begin_time'] = date('Y-m-d H:i:s');
        self::$INFO['now_time'] = self::$INFO['begin_time'];
        self::$INFO['memory_use'] = 0;
    }
    public static function _writeInit()
    {
        self::$INFO['write_success'] = 0;
        self::$INFO['write_error'] = 0;
        self::$INFO['begin_time'] = date('Y-m-d H:i:s');
        self::$INFO['now_time'] = self::$INFO['begin_time'];
        self::$INFO['have_user'] = 1;
        self::$INFO['memory_use'] = 0;
    }
    public static function writeShow()
    {
        if (0 == self::$INFO['have_user'])
        {
            $exit = 600;
            while ($exit) {
                system('clear');
                echo '--------------------------LYON-SPIDER-------------------------' . PHP_EOL;
                echo '--------------------------------------------------------------' . PHP_EOL . PHP_EOL;
                echo '=                       ' . '写Mysql成功次数 ：' . self::$INFO['write_success'] . PHP_EOL;
                echo '=                       ' . '获取信息失败次数：' . self::$INFO['write_error'] . PHP_EOL;
                echo '=                       ' . '开始时间        ：' . self::$INFO['begin_time'] . PHP_EOL;
                echo '=                       ' . '当前时间        ：' . self::$INFO['now_time'] . PHP_EOL;
                echo '=                       ' . '距下次开始      ：' . $exit . '秒' . PHP_EOL . PHP_EOL;
                echo '--------------------------  等待中  --------------------------' . PHP_EOL . PHP_EOL;
                echo '--------------------------------------------------------------' . PHP_EOL;
                echo '--------------------------LYON-SPIDER-------------------------' . PHP_EOL;
                $exit--;
                sleep(1);
            }
        }
        else
        {
            while (0) {
                system('clear');
                echo '--------------------------LYON-SPIDER-------------------------' . PHP_EOL;
                echo '--------------------------------------------------------------' . PHP_EOL . PHP_EOL;
                echo '=                       ' . '写Mysql成功次数 ：' . self::$INFO['write_success'] . PHP_EOL;
                echo '=                       ' . '获取信息失败次数：' . self::$INFO['write_error'] . PHP_EOL;
                echo '=                       ' . '开始时间        ：' . self::$INFO['begin_time'] . PHP_EOL;
                echo '=                       ' . '当前时间        ：' . self::$INFO['now_time'] . PHP_EOL;
                echo '--------------------------  写入中  --------------------------' . PHP_EOL . PHP_EOL;
                echo '--------------------------------------------------------------' . PHP_EOL;
                echo '--------------------------LYON-SPIDER-------------------------' . PHP_EOL;
            }
        }

    }

    public static function show()
    {
        $exit = 20;
        while ($exit)
        {
            system('clear');
            echo '--------------------------LYON-SPIDER-------------------------' . PHP_EOL;
            echo '--------------------------------------------------------------' . PHP_EOL . PHP_EOL;
            echo '=                       '. '成功次数   ：' . self::$INFO['success_page'] . PHP_EOL;
            echo '=                       '. '失败次数   ：'. self::$INFO['error_page'] . PHP_EOL;
            echo '=                       '. '开始时间   ：'. self::$INFO['begin_time'] . PHP_EOL;
            echo '=                       '. '当前时间   ：'. self::$INFO['now_time'] . PHP_EOL;
            echo '=                       '. '距下次开始 ：'. $exit . '秒' . PHP_EOL. PHP_EOL;
            if(1 == $exit)
            {
                echo '--------------------------  抓取中  --------------------------' . PHP_EOL. PHP_EOL;
            }
            else
            {
                echo '--------------------------  等待中  --------------------------' . PHP_EOL. PHP_EOL;
            }
            echo '--------------------------------------------------------------' . PHP_EOL;
            echo '--------------------------LYON-SPIDER-------------------------' . PHP_EOL;
            $exit--;
            sleep(1);
        }
    }
    public static function success()
    {
        self::$INFO['success_page']++;
    }
    public static function error()
    {
        self::$INFO['error_page']++;
    }
    public static function getTime()
    {
        self::$INFO['now_time'] = date('Y-m-d H:i:s');
    }
}